<template>
	<view>
		<view class="container">
			<view class="head">
				<swiper :indicator-dots="indicatorDots" :indicator-color="indicatorColor"
					:indicator-active-color="indicatorActiveColor" :autoplay="autoplay" :interval="interval"
					:duration="duration">
					<swiper-item>
						<view>
							<image src="@/static/banner01.jpg" mode="widthFix"></image>
						</view>
					</swiper-item>
					<swiper-item>
						<view>
							<image src="@/static/banner02.jpg" mode="widthFix"></image>
						</view>
					</swiper-item>
					<swiper-item>
						<view>
							<image src="@/static/banner03.jpg" mode="widthFix"></image>
						</view>
					</swiper-item>
				</swiper>
			</view>
			<view class="contentTitle">
				<view class="function">
					<image src="@/static/function.png"></image>
					<text>功能模块</text>
				</view>
			</view>
			<view class="content">
				<view class="consultation" @click="tz('/pages/consultation/consultation')">
					<text>心理咨询</text>
				</view>
				<view class="character">
					<view class="test" @click="tz('/pages/Selecttest/Selecttest')">
						<text>心理测评</text>
					</view>
					<view class="trends" @click="tz('/pages/article/article')">
						<text>倾诉社区</text>
					</view>
				</view>
			</view>
			<!-- 			<view class="footTitle">
				<view class="entertainment">
					<image src="@/static/entertainment.png"></image>
					<text>休闲娱乐</text>
				</view>
			</view> -->
			<view class="foot">
				<view class="decompression" @click="tz('/pages/relax/relax')">
					<text>解压室</text>
				</view>
				<view class="load" @click="tz('/pages/index/loading')">
					<text>loading</text>
				</view>
				<view class="book" @click="tz('/pages/book/book')">
					<text>书籍</text>
				</view>
				<view class="bookshelf" @click="tz('/pages/bookshelf/bookshelf')">
					<text>书架</text>
				</view>
			</view>

			<tabbar1></tabbar1>
		</view>

	</view>

	</view>
</template>

<script>
	import tabbar1 from "../../components/com/com-tabbar.vue"
	export default {
		components: {
			tabbar1
		},
		created() {
			//判断用户是否登陆,并验证token是否无效或者过期
			// this.hello();
		},
		onShow() {
			// this.setCurrentPage(this);
		},
		onLoad(option) {
			this.hello();
		},
		data() {
			return {
				indicatorDots: true,
				autoplay: true,
				interval: 3000,
				duration: 500,
				indicatorColor: "#292b40",
				indicatorActiveColor: "#ffffff",
			};
		},
		methods: {
			tz(page) {
				uni.navigateTo({
					url: page
				})
			},
			hello() { //测试携带token是否过期
				//获取当前登陆的用户
				let loginUser = uni.getStorageSync('loginUser');
				let token = uni.getStorageSync('token')
				console.log(loginUser)
				if (loginUser == null || loginUser == '' || token == null || token == '') { //用户为登陆,无需验证token
					uni.navigateTo({
						url: '../login/login'
					});
				}
				let that = this;
				//进行token验证
				uni.request({
					url: 'http://127.0.0.1:800/mhs/user/hello',
					method: 'GET',
					header: {
						'token': uni.getStorageSync('token') //携带token
					},
					success: (res) => {
						if (res.data == 'hello') {
							that.$websocket.commit('setUid', loginUser.id);
							that.$websocket.commit('webSocketInit', loginUser.id);
						} else { //用户未登录或者token过期
							uni.removeStorageSync('token');
							uni.removeStorageSync('loginUser');
							uni.showModal({
								title: 'token已过期,请重新登陆',
								content: '即将跳转登陆页',
								success: function(res) {
									if (res.confirm) {
										uni.navigateTo({
											url: '../login/login'
										});
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						}
					}
				})
			}
		}
	};
</script>

<style>
	.container {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.head {
		width: 90vw;
		height: 20vh;
	}

	.head image {
		width: 100%;
		max-height: 20vh;
	}

	.contentTitle {
		margin-top: 3vh;
		width: 90vw;
	}

	.function {
		display: flex;
	}

	.function image {
		width: 10vw;
		height: 5vh;
		margin-bottom: 1vh;
	}

	.contentTitle text {
		margin-left: 2vw;
		font-weight: bold;
		font-size: 23px;
		color: #7E84F7;
	}

	.content {
		/* 		margin-top: 3vh; */
		display: flex;
		width: 90vw;
		height: 30vh;
		border: 1px solid #C0C0C0;
		outline: none;
		border-radius: 5%;
		padding: 2vh;
		flex-wrap: wrap;

	}

	.content text {
		font-weight: bold;
		font-size: 30px;
	}

	.consultation {
		/* flex: 1; */
		width: 50%;
		height: 100%;
		border: 0px;
		outline: none;
		border-radius: 5%;
		background-image: url('https://img.tukuppt.com/ad_preview/00/82/37/60ebae526493c.jpg!/fw/780');
		background-size: 100% 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.character {
		flex: 1;
		display: flex;
		flex-direction: column;
		margin-left: 2vw;
		/* 		justify-content: center;
		align-items: center; */
	}

	.test {
		flex: 1;
		/* 		width: 100%;
		height: 50%; */
		border: 1px;
		outline: none;
		border-radius: 5%;
		background-image: url('https://seopic.699pic.com/photo/40244/9595.jpg_wh1200.jpg');
		background-size: 100% 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.trends {
		flex: 1;
		border: 1px solid #C0C0C0;
		outline: none;
		border-radius: 5%;
		background-image: url('https://seopic.699pic.com/photo/40219/3544.jpg_wh1200.jpg');
		background-size: 100% 100%;
		margin-top: 1vh;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.footTitle {
		margin-top: 3vh;
		width: 90vw;
	}

	.entertainment {
		display: flex;
	}

	.entertainment image {
		width: 10vw;
		height: 5vh;
		margin-bottom: 1vh;
	}

	.footTitle text {
		margin-left: 2vw;
		font-weight: bold;
		font-size: 23px;
		color: #7E84F7;
	}

	.foot {
		padding: 2vh;
		border: 1px solid #C0C0C0;
		outline: none;
		border-radius: 5%;
		display: flex;
		width: 90vw;
		height: 11vh;
		margin-top: 1vh;
		justify-content: space-around;
	}

	.foot text {
		font-weight: bold;
		font-size: 20px;
		/* 		color: #732BF5; */
	}

	.decompression {
		flex: 1;
		border: 1px solid #C0C0C0;
		outline: none;
		border-radius: 5%;
		background-image: url('https://seopic.699pic.com/photo/30657/6137.jpg_wh1200.jpg');
		background-size: 100% 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.load {
		flex: 1;
		border: 0px;
		outline: none;
		border-radius: 5%;
		background-image: url('https://seopic.699pic.com/photo/30641/1592.jpg_wh1200.jpg');
		background-size: 100% 100%;
		margin-left: 2vw;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.book {
		flex: 1;
		border: 0px;
		outline: none;
		border-radius: 5%;
		background-image: url('https://seopic.699pic.com/photo/50062/1999.jpg_wh1200.jpg');
		background-size: 100% 100%;
		margin-left: 2vw;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.bookshelf {
		flex: 1;
		border: 0px;
		outline: none;
		border-radius: 5%;
		background-image: url('https://seopic.699pic.com/photo/30231/7988.jpg_wh1200.jpg');
		background-size: 100% 100%;
		margin-left: 2vw;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>